<?
	require("required/dbconnect.php");
	require("required/function.php");
	
	
	mysql_query("truncate os_products");
	mysql_query("truncate os_productpic");
	
	$get_old=mysql_query("select * from po_products");
	
	while($a=mysql_fetch_array($get_old,MYSQL_ASSOC))
	{
		$old_id=$a['id'];
		$product_name=mysql_real_escape_string($a['product_name']);
		$clean_url=cleanURL($a['product_name']);
		$pic=$a['pic'].".gif";
		$width=$a['width'];
		$height=$a['height'];
		$caption=$a['caption'];
		$description_eng=mysql_real_escape_string($a['description']);
		$product_code=$a['product_code'];
		$featured=$a['featured'];
		
		mysql_query("insert into os_products
					(cat_id,sub_cat_id,product_name_eng,display_name,clean_url,product_code,featured,description_eng,hide_at_products,create_datetime,status)
					values(1,1,'$product_name','$product_name','$clean_url','$product_code',$featured,'$description_eng',0,now(),1)")or die(mysql_error());
					
		$id=mysql_insert_id();			
		
		if($pic!="")
		{
			mysql_query("insert into os_productpic(product_id,order_id,name,caption,width,height,create_datetime)
					   values($id,'0','$pic','$caption',$width,$height,now())")or die(mysql_error());
		}
		
		
		$get_pic=mysql_query("select * from po_productpic where product_id=$old_id");
		
		while($p=mysql_fetch_array($get_pic,MYSQL_ASSOC))
		{
			$order_id=$p['order_id'];
			$name=mysql_real_escape_string($p['name']);		
			$width=$p['width'];
			$height=$p['height'];
			$caption=mysql_real_escape_string($p['caption']);
			
			mysql_query("insert into os_productpic(product_id,order_id,name,caption,width,height,create_datetime)
					   values($id,'$order_id','$name','$caption',$width,$height,now())")or die(mysql_error());
			
		}
							
			
	}
	
	echo "done";
?>